package com.java.comprehensive.arithmetic.leecode.easy;

import java.util.Stack;

public class LeetCode_232 {

    static class MyQueue {

        private Stack<Integer> enterStack;
        private Stack<Integer> outStack;

        public MyQueue() {
            this.enterStack = new Stack<>();
            this.outStack = new Stack<>();
        }

        public void push(int x) {
            enterStack.push(x);
        }

        public int pop() {
            if (outStack.isEmpty()) {
                while (!enterStack.isEmpty()) {
                    outStack.push(enterStack.pop());
                }
            }
            return outStack.pop();
        }

        public int peek() {
            if (outStack.isEmpty()) {
                while (!enterStack.isEmpty()) {
                    outStack.push(enterStack.pop());
                }
            }
            return outStack.peek();
        }

        public boolean empty() {
            return enterStack.isEmpty() && outStack.isEmpty();
        }
    }

    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(2);
        myQueue.push(3);
        System.out.println(myQueue.pop());
        myQueue.push(4);
        System.out.println(myQueue.peek());
    }
}
